<%@page import="com.jspsmart.upload.Request"%>
<%@page import="com.jspsmart.upload.SmartUpload"%>
<%@page import="cn.yunhe.biz.NewsBiz"%>
<%@page import="cn.yunhe.entity.Cate"%>
<%@page import="cn.yunhe.entity.News"%>
<%@page import="cn.yunhe.entity.Admin"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		
		SmartUpload su=new SmartUpload();
		su.initialize(pageContext);
		su.setCharset("UTF-8");
		su.upload();
		su.save("admin/upfiles");
		
		Request req=  su.getRequest();
		
		String title=req.getParameter("title");
		String content=req.getParameter("content");
		
		String pic=su.getFiles().getFile(0).getFileName();
		
		
		//分别得到管理员的id和类别的id
		Admin admin=(Admin)session.getAttribute("admin");
		int c=Integer.parseInt(req.getParameter("cate"));
		Cate cate=new Cate(c);
		
		
		News news=new News(title,content,new Date(),pic,admin,cate);
		
		NewsBiz newsBiz=new NewsBiz();
		boolean flag=newsBiz.addNews(news);
		
		if(flag){
			request.getRequestDispatcher("newsList.jsp").forward(request, response);
		}else{
			response.sendRedirect("addNews.jsp");
		}
		
		
		
%>
